﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef SpriteFrameCache_h__
#define SpriteFrameCache_h__


#include <unordered_map>
#include <string>

#include "../utility/MacroTool.h"
#include "../utility/NonCopyable.h"
#include "../utility/SmartPtrDef.h"


namespace SkyEngine2d
{
	
	/*!
	 \brief 精灵帧缓存
	 \details
	*/
	class SGE_API SpriteFrameCache
		:public NonCopyable
	{
	public:
	
		//! 构造
		SpriteFrameCache();
	
		//! 析构 
		~SpriteFrameCache();
	
		//! 从纹理集合中添加精灵帧
		/*!
		\param const std::wstring & imagepack_file_name 纹理集合的路径 （xml格式的文件）
		\param const std::wstring& image_path 纹理的路径
		\return void 
		*/
		bool addSpriteFramesWithImagePack(const std::wstring & imagepack_file_name,const std::wstring& image_path);
	
		//! 添加精灵帧
		/*!
		\param const SpriteFrameSharedPtr & sprite_frame 精灵帧指针
		\param const std::wstring & name 精灵帧的名字，名字需要唯一
		\return void 
		*/
		bool addSpriteFrame(const SpriteFrameSharedPtr & sprite_frame, const std::wstring & name);
	
		//! 获取精灵帧
		/*!
		\param const std::wstring & name 精灵帧的名字
		\return SpriteFrameSharedPtr 
		*/
		SpriteFrameSharedPtr getSpriteFrame(const std::wstring & name);
	
		//! 移除精灵帧 
		/*!
		\param const std::wstring & name 精灵帧的名字
		\return void 
		*/
		void removeSpriteFrame(const std::wstring & name);
	
		//! 移除全部精灵帧
		/*!
		\param const std::wstring & name
		\return void 
		*/
		void removeAllSpriteFrame();
	
	
	private:
		struct Imp;
		std::unique_ptr<Imp>	 m_imp;
		std::unordered_map<std::wstring, SpriteFrameSharedPtr> m_name2SpriteFramePtr; /*!< 从名字到精灵帧的映射. */
	};
	
}


#endif // SpriteFrameCache_h__

